package com.jxs.android.weiget;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.jxs.android.util.StringUtils;
import com.telecom.weixi.R;

public class BuAlertDailog {

	static public interface AlertOkAndCancelListener {
		String getOkText(Context context);

		String getCancleText(Context context);

		void okLogic(Dialog dialog);

		void cancelLogic(Dialog dialog);
	}

	static public interface IPhoneAlertDailog {
		String getOkText(Context context);

		void okLogic(Dialog dialog);
	}

	public static Dialog builder(Context context, String title, final String message, final AlertOkAndCancelListener alertOkAndCancelListener) {
		final Dialog dialog = new Dialog(context, R.style.IPone_Dialog_Bg);
		dialog.setContentView(R.layout.bu_iphone_alert_r_okcanceldialogview);
		((TextView) dialog.findViewById(R.id.dialog_title)).setText(title);
		((TextView) dialog.findViewById(R.id.dialog_message)).setText(message);
		String okText = context.getString(R.string.promp_confirm);
		String cancelText = context.getString(R.string.promp_cancel);
		if (null != alertOkAndCancelListener && StringUtils.isEmpety(alertOkAndCancelListener.getOkText(context))) {
			okText = alertOkAndCancelListener.getOkText(context);
		}
		if (null != alertOkAndCancelListener && StringUtils.isEmpety(alertOkAndCancelListener.getCancleText(context))) {
			cancelText = alertOkAndCancelListener.getCancleText(context);
		}
		((Button) dialog.findViewById(R.id.ok)).setText(okText);
		((Button) dialog.findViewById(R.id.cancel)).setText(cancelText);
		(dialog.findViewById(R.id.ok)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (null != alertOkAndCancelListener) {
					alertOkAndCancelListener.okLogic(dialog);
				}
			}
		});
		(dialog.findViewById(R.id.cancel)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (null != alertOkAndCancelListener) {
					alertOkAndCancelListener.cancelLogic(dialog);
				}
			}
		});
		return dialog;
	}

	public static Dialog builder(Context context, String pTitle, final String pMsg, final IPhoneAlertDailog alertOkListener) {
		final Dialog dialog = new Dialog(context, R.style.IPone_Dialog_Bg);
		dialog.setContentView(R.layout.bu_iphone_alert_r_okdialogview);
		((TextView) dialog.findViewById(R.id.dialog_title)).setText(pTitle);
		((TextView) dialog.findViewById(R.id.dialog_message)).setText(pMsg);
		String okText = context.getString(R.string.promp_confirm);
		if (null != alertOkListener && StringUtils.isEmpety(alertOkListener.getOkText(context))) {
			okText = alertOkListener.getOkText(context);
		}
		((Button) dialog.findViewById(R.id.ok)).setText(okText);
		(dialog.findViewById(R.id.ok)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (null != alertOkListener) {
					alertOkListener.okLogic(dialog);
				}
			}
		});
		return dialog;

	}

}
